package com.kanan.vueupload.vo;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author kananan
 * @date 2021/1/17
 */
@Data
@NoArgsConstructor
@SuppressWarnings("rawtypes")
public class Result<T extends Object> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 是否跳过
     */
    private Boolean skip;

    /**
     * 响应数据
     */
    private T data;

    public Result(String msg, T data) {
        this.msg = msg;
        this.data = data;
        this.code = 200;
    }

    public Result(String msg, Boolean skip, T data) {
        this.code = 200;
        this.msg = msg;
        this.skip = skip;
        this.data = data;
    }

    public Result success(String msg, T data){
        Result<Object> result = new Result<>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result success(String msg){
        Result<Object> result = new Result<>();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }

    public static Result success(){
        Result<Object> result = new Result<>();
        result.setCode(200);
        result.setMsg("上传成功");
        return result;
    }


    public static Result error(){
        Result<Object> result = new Result<>();
        result.setCode(500);
        result.setMsg("上传失败");
        return result;
    }

    public static Result error(String msg){
        Result<Object> result = new Result<>();
        result.setCode(500);
        result.setMsg(msg);
        return result;
    }

    public static Result error(Integer code,String msg){
        Result result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
